def matches(dev, mode) :
    import re
    return (
        re.search(r"""
            Saitek_P2500_Rumble_Force_Pad
                |
            Saitek_P2900_Wireless_Pad
        """, dev, re.X) and mode == "fly"
    )

def handler(self, event) :
    import osg
    if event["mode"] == "analog" :
        self.velocity = osg.Matrixd()
        self.velocity.postMult(
            osg.Matrixd.translate(
                ( event["data"][0] + event["data"][4] )
                    * self.nav_scale["translation"][0],
                -event["data"][5] * self.nav_scale["translation"][2],
                event["data"][1] * self.nav_scale["translation"][1],
            )
        )
        self.velocity.postMult(
            osg.Matrixd.rotate(
                event["data"][2] * self.nav_scale["rotation"],
                -1, 0, 0
            )
        )
        self.velocity.postMult(
            osg.Matrixd.rotate(
                event["data"][3] * self.nav_scale["rotation"],
                0, -1, 0 
            )
        )
    elif event["mode"] == "button" and event["data"] == [ 6, "pressed" ] :      
        self.button_velocity.postMult(                                          
            osg.Matrixd.rotate(                                                 
                self.nav_scale["rotation"], 0, 0, -1                            
            )
        )
    elif event["mode"] == "button" and event["data"] == [ 6, "released" ] :
        self.button_velocity = osg.Matrixd()
    elif event["mode"] == "button" and event["data"] == [ 7, "pressed" ] :
        self.button_velocity.postMult(
            osg.Matrixd.rotate(
                self.nav_scale["rotation"], 0, 0, 1
            )
        )
    elif event["mode"] == "button" and event["data"] == [ 7, "released" ] :
        self.button_velocity = osg.Matrixd()
    elif event["mode"] == "button" and event["data"][0] == 9 :
        self.velocity = osg.Matrixd()
        self.button_velocity = osg.Matrixd()

